import java.io.*;

public class MyCP{
public static void main(String[] args) throws IOException {
//输入十进制文本
String filepath = "/zzz/MyCP/shuru.txt";
String s =dataInputStream(filepath);
//将得到的二进制数存成文本
FileOutputStream fps = new FileOutputStream("/zzz/MyCP/shuchu.txt");
fps.write(s.getBytes());
fps.close();
}
public static String dataInputStream(String filepath) throws IOException {
File file = new File(filepath);
DataInputStream dps = new DataInputStream(new FileInputStream(file));
StringBuilder byData = new StringBuilder();
byte bt = 0;
for(int i=0;i<file.length();i++) {//返回一个字符串二进制的无符号整数
bt = dps.readByte();//按照字节读取
String str = Integer.toBinaryString(bt);
if(str.length() == 1) {
str = "0"+str;
}
byData.append(str.toUpperCase());
}
return byData.toString();
}

}
